package com.dinadi.yidi.ui.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.dinadi.yidi.R;
import com.dinadi.yidi.base.BaseActivity;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * author: JiaYu.He
 * Date: 2018/5/8
 * Time: 16:41
 */

public class ClassificationActivity extends BaseActivity {
    private View view;
    private TextView tvTitle;
    /*判断网络*/
    private GridView gridview;
    private int[] image = {R.drawable.designer_classification_zhongguoyang, R.drawable.designer_classification_recommend, R.drawable.designer_classification_news,
            R.drawable.designer_classification_furniture, R.drawable.designer_classification_home,
            R.drawable.designer_classification_glasses, R.drawable.designer_classification_toys, R.drawable.designer_classification_shijiuchaxiang, R.drawable.designer_classification_wenboyishu};


    @Override
    protected View getLayout() {
        view = LayoutInflater.from(ClassificationActivity.this).inflate(R.layout.fragment_classification, null);
        return view;
    }

    @Override
    protected void noWifiRefresh() {

    }

    @Override
    protected void initView() {
        changePager(2);
        tvTitle = (TextView) view.findViewById(R.id.text_title);
        tvTitle.setText(R.string.text_classification);
        //显示GridView的界面
        gridview = (GridView) view.findViewById(R.id.classification_gridview);
        ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();
        // 使用HashMap将图片添加到一个数组中，注意一定要是HashMap<String,Object>类型的，因为装到map中的图片要是资源ID，而不是图片本身
        // 如果是用findViewById(R.drawable.image)这样把真正的图片取出来了，放到map中是无法正常显示的
        for (int i = 0; i < 9; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("image", image[i]);
            imagelist.add(map);
        }
        // 使用simpleAdapter封装数据，将图片显示出来
        // 参数一是当前上下文Context对象
        // 参数二是图片数据列表，要显示数据都在其中
        // 参数三是界面的XML文件，注意，不是整体界面，而是要显示在GridView中的单个Item的界面XML
        // 参数四是动态数组中与map中图片对应的项，也就是map中存储进去的相对应于图片value的key
        // 参数五是单个Item界面XML中的图片ID
        SimpleAdapter simpleAdapter = new SimpleAdapter(ClassificationActivity.this, imagelist,
                R.layout.adapter_classification_item, new String[]{"image"}, new int[]{
                R.id.item_img});
        // 设置GridView的适配器为新建的simpleAdapter
        gridview.setAdapter(simpleAdapter);
    }

    @Override
    protected void initListener() {
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                HashMap<String, String> map = new HashMap<String, String>();
                Intent intent = new Intent();
                intent.setClass(ClassificationActivity.this, DesignerCategoryActivity.class);
                if (position == 0) {
                   /*中国样*/
                    map.put("type", "中国样");
                    intent.putExtra("category", "9");
                } else if (position == 1) {
                    /*推荐*/
                    map.put("type", "推荐");
                    intent.putExtra("category", "1");
                } else if (position == 2) {
                   /*最新*/
                    map.put("type", "最新");
                    intent.putExtra("category", "2");
                } else if (position == 3) {
                   /*家具*/
                    map.put("type", "家具");
                    intent.putExtra("category", "3");
                } else if (position == 4) {
                   /*居家*/
                    map.put("type", "居家");
                    intent.putExtra("category", "4");

                } else if (position == 5) {
                   /*配饰*/
                    map.put("type", "配饰");
                    intent.putExtra("category", "5");
                } else if (position == 6) {
                   /*童趣*/
                    map.put("type", "童趣");
                    intent.putExtra("category", "6");
                } else if (position == 7) {
                   /*诗酒茶香*/
                    map.put("type", "诗酒茶香");
                    intent.putExtra("category", "7");
                } else if (position == 8) {
                   /*文博艺术*/
                    map.put("type", "文博艺术");
                    intent.putExtra("category", "8");

                }
                startActivity(intent);
                MobclickAgent.onEvent(ClassificationActivity.this, "classification", map);

            }
        });

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void clickEvent(View v) {

    }
}
